package com.qing.study.controller;

import com.qing.study.service.AsyncService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "异步功能")
public class AsyncController {

    @Autowired
    private AsyncService asyncService;

    @ApiOperation("没有开启异步功能")
    @GetMapping("noAsync")
    public String noAsync() throws InterruptedException {
        Thread.sleep(3000);
        return "OK!!!";
    }

    @ApiOperation("使用@Async注解开启异步功能，秒返回")
    @GetMapping("yesAsync")
    public String yesAsync() throws InterruptedException {
        asyncService.asyncMethod();
        return "OK!!!";
    }
}
